

import 'package:erp/UI/Components/EventfulState.dart';
import 'package:flutter/material.dart';

typedef EmbeddableWidgetBuilder = Widget Function(BuildContext context, EventfulState<EmbeddableStatefulWidget> state);
typedef InitEvent = void Function(EventfulState state);

class EmbeddableStatefulWidget extends StatefulWidget {
  EmbeddableWidgetBuilder widgetBuilder;
  InitEvent initEvent;
  EmbeddableStatefulWidget(this.widgetBuilder, this.initEvent);
  @override
  State<StatefulWidget> createState() => EmbeddableState();
}
class EmbeddableState extends EventfulState<EmbeddableStatefulWidget> {
  @override
  Widget build(BuildContext context) {
    return widget.widgetBuilder(context, this);
  }

  @override
  void initState() {
    (widget.initEvent ?? (EventfulState state){})(this);
    super.initState();
  }
}

Widget EmbeddedWidget({Widget widgetBuilder(BuildContext context, EventfulState<EmbeddableStatefulWidget> state), initEvent(EventfulState state) = null}) => EmbeddableStatefulWidget(widgetBuilder, initEvent);